{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 65\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write assert statements to verify that every number in the list [2,4,6,8] is even._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use \"assert expression\" to make assertion._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = [2, 4, 5, 6]\n",
    "for i in data:\n",
    "    assert i % 2 == 0, \"{} is not an even number\".format(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 66\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write a program which accepts basic mathematic expression from console and print the evaluation result._**\n",
    "\n",
    "> **_Example:\n",
    "> If the following n is given as input to the program:_**\n",
    "\n",
    "\n",
    "> 35 + 3\n",
    "\n",
    "\n",
    "> **_Then, the output of the program should be:_**\n",
    "\n",
    "\n",
    "> 38\n",
    "\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use eval() to evaluate an expression._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "expression = input()\n",
    "ans = eval(expression)\n",
    "print(ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 67\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please write a binary search function which searches an item in a sorted list. The function should return the index of element to be searched in the list._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use if/elif to deal with conditions._**\n",
    "\n",
    "---\n",
    "\n",
    "**Solutions:**\n",
    "\n",
    "### Solution by AasaiAlangaram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def binary_search_Ascending(array, target):\n",
    "    lower = 0\n",
    "    upper = len(array)\n",
    "    print(\"Array Length:\", upper)\n",
    "    while lower < upper:\n",
    "        x = (lower + upper) // 2\n",
    "        print(\"Middle Value:\", x)\n",
    "        value = array[x]\n",
    "        if target == value:\n",
    "            return x\n",
    "        elif target > value:\n",
    "            lower = x\n",
    "        elif target < value:\n",
    "            upper = x\n",
    "\n",
    "\n",
    "Array = [1, 5, 8, 10, 12, 13, 55, 66, 73, 78, 82, 85, 88, 99]\n",
    "print(\"The Value Found at Index:\", binary_search_Ascending(Array, 82))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "**OR**\n",
    "\n",
    "### Solution by yuan1z: Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "idx = 0\n",
    "\n",
    "\n",
    "def bs(num, num_list):\n",
    "    global idx\n",
    "    if len(num_list) == 1:\n",
    "        if num_list[0] == num:\n",
    "            return idx\n",
    "        else:\n",
    "            return \"No exit in the list\"\n",
    "    elif num in num_list[: len(num_list) // 2]:\n",
    "        return bs(num, num_list[: len(num_list) // 2])\n",
    "    else:\n",
    "        idx += len(num_list) // 2\n",
    "    return bs(num, num_list[len(num_list) // 2 :])\n",
    "\n",
    "\n",
    "print(bs(66, [1, 5, 8, 10, 12, 13, 55, 66, 73, 78, 82, 85, 88, 99, 100]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 68\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please generate a random float where the value is between 10 and 100 using Python module._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use random.random() to generate a random float in [0,1]._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "\n",
    "rand_num = random.uniform(10, 100)\n",
    "print(rand_num)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 69\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please generate a random float where the value is between 5 and 95 using Python module._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use random.random() to generate a random float in [0,1]._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "\n",
    "rand_num = random.uniform(5, 95)\n",
    "print(rand_num)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
